﻿
using System ;

using MskEdit.Sdk ;


namespace MskEdit.Msk.Representation
{

    public class StringField
    {
        private SdkSubrange subrange_ ;
        
        
        private StringField( SdkSubrange subrange ) {
            subrange_ = subrange ;
        }
            
           
        public string TryFrom( string line, string fallbackValue ) { 
            return SdkSubstring.TryFrom( line, subrange_, fallbackValue ) ; 
        }
       
        public string TryInsert( string line, string value, string fallbackValue ) {
            return SdkSubstring.TryInsert( line, subrange_, value, fallbackValue ) ; 
        }
                
        public string PadRight( string str ) {
        
            if ( str.Length > subrange_.Length )
                throw new SdkException( "String is longer than length of subrange." ) ;
        
            string newStr = str ;
            
            newStr = newStr.PadRight( subrange_.Begin ) ;
            
            return newStr ;
        }
        
                
        public string AppendTo( string line, string str ) {
        
            if ( line.Length > subrange_.Begin )
                throw new SdkException( "Line is longer than start of subrange." ) ;
            
            string newLine = line ;
            newLine = newLine.PadRight( subrange_.Begin ) ;
            newLine = newLine + str ;
            newLine = newLine.PadRight( subrange_.End ) ;
            
            return newLine ;
        }


        static public StringField FieldName      = new StringField( FieldSubrange.FieldName ) ;        
        static public StringField Len            = new StringField( FieldSubrange.Len ) ;        
        static public StringField Yk             = new StringField( FieldSubrange.Yk ) ;
        static public StringField Xk             = new StringField( FieldSubrange.Xk ) ;        
        static public StringField Type           = new StringField( FieldSubrange.Type ) ;
        static public StringField Decimals       = new StringField( FieldSubrange.Decimals ) ;
        static public StringField PageCode       = new StringField( FieldSubrange.PageCode ) ;
        static public StringField Caption        = new StringField( FieldSubrange.Caption ) ;        
        static public StringField FunCode        = new StringField( FieldSubrange.FunCode ) ;
        static public StringField AcadY          = new StringField( FieldSubrange.AcadY ) ;
        static public StringField AcadX          = new StringField( FieldSubrange.AcadX ) ;
        
        static public StringField AcadHeight     = new StringField( FieldSubrange.AcadHeight ) ;
        static public StringField AcadStyle      = new StringField( FieldSubrange.AcadStyle ) ;
        static public StringField AcadAngle      = new StringField( FieldSubrange.AcadAngle ) ;
        static public StringField AcadLayer      = new StringField( FieldSubrange.AcadLayer ) ;
        static public StringField AcadAlignment  = new StringField( FieldSubrange.AcadAlignment ) ;
        
        static public StringField HelpText       = new StringField( FieldSubrange.HelpText ) ;
        static public StringField PresetValue    = new StringField( FieldSubrange.PresetValue ) ;
        static public StringField AcadY2         = new StringField( FieldSubrange.AcadY2 ) ;
        static public StringField AcadX2         = new StringField( FieldSubrange.AcadX2 ) ;
        static public StringField AcadBlock      = new StringField( FieldSubrange.AcadBlock ) ;
        static public StringField AcadTag        = new StringField( FieldSubrange.AcadTag ) ;
        static public StringField Language       = new StringField( FieldSubrange.Language ) ;
        
    }
}
